About 923 letters

About 5 minutes

#hasattr

Description: Check if an attribute exists. See also: delattr, getattr, setattr

def hasattr(obj, name: str): ''' Check if an attribute exists :param obj: An object :param name: The name of the attribute :return: True if the attribute exists, otherwise False '''

Example:

class Person: def __init__(self, name, age): self.name = name self.age = age p = Person("Alice", 30) print(hasattr(p, 'name')) # True print(hasattr(p, 'age')) # True print(hasattr(p, 'sex')) # False

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

Created in 6/9/2025

Updated in 6/9/2025